package com.zh.mediaservice.service.impl;

import com.zh.mediacommon.constant.ReserveConstant;
import com.zh.mediapojo.vo.ReserveVO;
import com.zh.mediaservice.mapper.DoctorMapper;
import com.zh.mediaservice.service.DoctorReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class DoctorReserveServiceImpl implements DoctorReserveService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private DoctorMapper doctorMapper;
    @Override
    public void setReserveNum(Integer amNum, Integer pmNum, Integer doctorId) {
        if(amNum!=null)
            redisTemplate.opsForHash().put(doctorId.toString(), ReserveConstant.MAX_NUM_AM,amNum);
        else
            redisTemplate.opsForHash().put(doctorId.toString(), ReserveConstant.MAX_NUM_AM, ReserveConstant.DEFAULT_MAX_NUM_AM);
        if(pmNum!=null)
            redisTemplate.opsForHash().put(doctorId.toString(), ReserveConstant.MAX_NUM_PM,pmNum);
        else
            redisTemplate.opsForHash().put(doctorId.toString(), ReserveConstant.MAX_NUM_PM, ReserveConstant.DEFAULT_MAX_NUM_PM);
    }

    @Override
    public ReserveVO getReserveNum(Integer doctorId) {
       ReserveVO reserveVO =  doctorMapper.getReserveNum(doctorId);
        return reserveVO;
    }
}
